package com.example.mytayunapi.Controller;

import com.example.mytayunapi.Entity.commentInfo;
import com.example.mytayunapi.Vo.UserOrderCommentOrder;
import com.github.pagehelper.PageInfo;
import com.example.mytayunapi.Service.commentInfoService;
import com.example.mytayunapi.Vo.UserCommentOrder;
import com.example.mytayunapi.Vo.UserProductImage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("approvalcomment")
public class commentInfoController {
    @Autowired
    private commentInfoService commentinfoservice;

    //http://localhost:8080/approvalcomment/query
    @GetMapping("query")
    public List<UserCommentOrder> getOrderUserComment(){
        return commentinfoservice.getOrderUserComment();
    }

    //http://localhost:8080/approvalcomment/queryid
    @GetMapping("queryid")
    public List<UserCommentOrder> getOrderUserCommentId(Integer Comment_id){
        List<UserCommentOrder> Id = null;
        if(Comment_id == null){
            Id = commentinfoservice.getOrderUserComment();
        }else{
            Id = commentinfoservice.getCommentUserOrderId(Comment_id);
        }
        return Id;
    }


    //http://localhost:8080/approvalcomment/update
    @PostMapping("update")
    public Integer updateCommentInfoByOrderId(@RequestBody UserCommentOrder commentStatusInfo){
        return commentinfoservice.updateCommentInfoByOrderId(commentStatusInfo);
    }

    //http://localhost:8080/approvalcomment/insertcom
    @PostMapping("insertcom")
    public Integer insertCommentInfoByOrderId(@RequestBody commentInfo commentinfo){
        return commentinfoservice.insertCommentInfoByOrderId(commentinfo);
    }


    //http://localhost:8080/approvalcomment/page       分页
    @GetMapping("page")
    public PageInfo<UserCommentOrder> pageInfo(@RequestParam Integer page, @RequestParam Integer size){
        return commentinfoservice.getPageInfo(page,size);
    }

    //http://localhost:8080/approvalcomment/queryStatus
    @GetMapping("queryStatus")
    public List<UserCommentOrder> getCommentStatus(String Comment_status){
        return commentinfoservice.getCommentUserOrderStatus(Comment_status);
    }


    //http://localhost:8080/approvalcomment/queryStatusNa
    @GetMapping("queryStatusNa")
    public List<UserCommentOrder> getCommentStatusNa(String Comment_status){
        return commentinfoservice.getCommentUserOrderStatusNa(Comment_status);
    }

    //http://localhost:8080/approvalcomment/queryConArank
    @GetMapping("queryConArank")
    public List<UserCommentOrder> getConArank(@RequestParam(value = "keyword",required = false) String keyword,
                                              @RequestParam(value = "Comment_rank",required = false) String Comment_rank){
        if(keyword != null && Comment_rank != null){
            return commentinfoservice.getCommentcontentArank(keyword,Comment_rank);
        }else if(keyword != null){
            return commentinfoservice.getCommentcontent(keyword);
        }else if(Comment_rank != null){
            return commentinfoservice.getCommentrank(Comment_rank);
        }else{
            return Collections.emptyList();
        }

    }

    //http://localhost:8080/approvalcomment/queryConArankNA
    @GetMapping("queryConArankNA")
    public List<UserCommentOrder> getConArankNA(@RequestParam(value = "keyword",required = false) String keyword,
                                                @RequestParam(value = "Comment_status",required = false) String Comment_status){
        if(keyword != null && Comment_status != null){
            return commentinfoservice.getCommentcontentArankNA(keyword,Comment_status);
        }else if(keyword != null){
            return commentinfoservice.getCommentcontent(keyword);
        }else if(Comment_status != null){
            return commentinfoservice.getCommentUserOrderStatusNa(Comment_status);
        }else{
            return Collections.emptyList();
        }
    }

    //http://localhost:8080/approvalcomment/queryContent
    @GetMapping("queryContent")
    public List<UserCommentOrder> getCommentContent(String keyword){
        return commentinfoservice.getCommentcontent(keyword);
    }

    //http://localhost:8080/approvalcomment/queryRank
    @GetMapping("queryRank")
    public List<UserCommentOrder> getCommentRank(String Comment_rank){
        return commentinfoservice.getCommentrank(Comment_rank);
    }

    //http://localhost:8080/approvalcomment/pingjia
    @GetMapping("/pingjia")
    public List<UserOrderCommentOrder> getMaijia(@RequestParam String School_degree){
        return commentinfoservice.getMaijiaPingjia(School_degree);
    }
}
